/**
 * https://leetcode.cn/problems/range-addition-ii/
 */
function maxCount(m: number, n: number, ops: number[][]): number {
  let minA = m,
    minB = n;
  for (const op of ops) {
    minA = Math.min(minA, op[0]);
    minB = Math.min(minB, op[1]);
  }
  return minA * minB;
}

// 不通过
function maxCount2(m: number, n: number, ops: number[][]): number {
  if (ops.length === 0) return m * n;
  let ans = 0,
    maxNum = 0;

  // 创建一个 m * n 的二位数组
  const arr = new Array(m).fill(0).map(() => new Array(n).fill(0));
  const set = new Set<string>();

  for (let [x, y] of ops) {
    const markLabel = `${x},${y}`;
    if (set.has(markLabel)) continue;
    set.add(markLabel);
    let currentNum = 0;
    for (let row = 0; row < x; row++) {
      for (let col = 0; col < y; col++) {
        currentNum = arr[row][col] + 1;
        arr[row][col] = currentNum;
      }
    }
    if (currentNum > maxNum) {
      ans = Math.max(ans, x * y);
      maxNum = currentNum;
    }
  }

  return ans;
}
